package GUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

public class CriaER extends JFrame {

	private JPanel contentPane;
	private JTextField expr;
	private JTextField alfa;
	//public static Logico1 logico = new Logico1();
	private String alfabeto;
	private String expressao;

	/**
	 * Launch the application.
	 */
	 /*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CriaER frame = new CriaER();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/

	static CriaER frame;
	public static void run() {
		try {
			frame = new CriaER();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * Create the frame.
	 */
	public CriaER() {
		setType(Type.UTILITY);
		setTitle("Criar ER");
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setToolTipText("");
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblInsiraOAlfabeto = new JLabel("Insira o Alfabeto da Express\u00E3o Regular: ex.: abc");
		//lblInsiraOAlfabeto.requestFocus();
		lblInsiraOAlfabeto.setFont(new Font("Californian FB", Font.BOLD, 16));
		lblInsiraOAlfabeto.setBounds(62, 31, 307, 20);
		contentPane.add(lblInsiraOAlfabeto);
		
		alfa = new JTextField();
		alfa.addFocusListener(new FocusListener() {
			boolean ctrl = true;
			@Override
			public void focusLost(FocusEvent e) {
					
			}
			
			@Override
			public void focusGained(FocusEvent e) {
				
				if(ctrl){
					alfa.setText("");
					alfa.setForeground(Color.BLACK);
					ctrl = false;
				}
				
			}
		});
		alfa.setHorizontalAlignment(SwingConstants.CENTER);
		alfa.setForeground(Color.GRAY);
		alfa.setText("abc");
		alfa.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		
		alfa.setBounds(10, 68, 414, 26);
		contentPane.add(alfa);
		alfa.setColumns(10);
		
		
		
		JLabel lblInsiraSuaExpreo = new JLabel("Insira sua Express\u00E3o Regular:");
		lblInsiraSuaExpreo.setFont(new Font("Californian FB", Font.BOLD, 16));
		lblInsiraSuaExpreo.setBounds(135, 115, 188, 20);
		contentPane.add(lblInsiraSuaExpreo);
		
		expr = new JTextField();
		expr.addFocusListener(new FocusListener() {
			boolean ctrl = true;
			@Override
			public void focusLost(FocusEvent e) {
							
			}
			
			@Override
			public void focusGained(FocusEvent e) {
				if(ctrl){
					expr.setText("");
					expr.setForeground(Color.BLACK);
					ctrl = false;
				}
			}
		});
		expr.setForeground(Color.GRAY);
		expr.setHorizontalAlignment(SwingConstants.CENTER);
		expr.setText("a*(b?c|d)*");
		expr.setBounds(10, 146, 414, 26);
		contentPane.add(expr);
		expr.setColumns(10);
		
		
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
		btnCancelar.setBounds(135, 211, 89, 23);
		contentPane.add(btnCancelar);
		
		JButton btnOk = new JButton("Criar");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					alfabeto = alfa.getText();
					expressao = expr.getText();
					//logico.incluirER(alfabeto, expressao);
					frame.dispose();
					
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		btnOk.setBounds(234, 211, 89, 23);
		contentPane.add(btnOk);
	}
}
